function zstring = zerodstring(zstring, zlength)
% zerodstring  - fill a string with zero chars and fix length
%
% FORMAT:       zstring = zerodstring(zstring, zlength)
%
% Input fields:
%
%       zstring     string to be zero-char filled
%       zlength     fixed string length
%
% Output fields:
%
%       zstring     zero-char filled string

% Version:  v0.7f
% Build:    8110521
% Date:     Nov-05 2008, 9:00 PM CET
% Author:   Jochen Weber, SCAN Unit, Columbia University, NYC, NY, USA
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 2 || ...
   ~ischar(zstring) || ...
    numel(zstring) ~= size(zstring, 2) || ...
   ~isa(zlength, 'double') || ...
    numel(zlength) ~= 1 || ...
    isnan(zlength) || ...
    isinf(zlength) || ...
    zlength < 0
    error( ...
        'BVQXtools:BadArgument', ...
        'Invalid argument given to %s.', ...
        mfilename ...
    );
end

% fix arguments
zlength = floor(zlength);
zstring = [zstring(:)', char(zeros(1, zlength))];
zstring = zstring(1:zlength);
